import request from './request'

/**
 * 工作流 API
 */

// 获取工作流列表
export const getWorkflowList = (params) => {
  return request({
    url: '/workflows',
    method: 'get',
    params
  })
}

// 获取工作流详情
export const getWorkflowDetail = (id) => {
  return request({
    url: `/workflows/${id}`,
    method: 'get'
  })
}

// 创建工作流
export const createWorkflow = (data) => {
  return request({
    url: '/workflows',
    method: 'post',
    data
  })
}

// 更新工作流
export const updateWorkflow = (id, data) => {
  return request({
    url: `/workflows/${id}`,
    method: 'put',
    data
  })
}

// 删除工作流
export const deleteWorkflow = (id) => {
  return request({
    url: `/workflows/${id}`,
    method: 'delete'
  })
}

// 运行工作流
export const runWorkflow = (id, data) => {
  return request({
    url: `/workflows/${id}/run`,
    method: 'post',
    data
  })
}

// 获取工作流实例列表
export const getWorkflowInstances = (params) => {
  return request({
    url: '/workflows/instances/list',
    method: 'get',
    params
  })
}

// 获取工作流实例详情
export const getWorkflowInstanceDetail = (id) => {
  return request({
    url: `/workflows/instances/${id}`,
    method: 'get'
  })
}

// 暂停工作流实例
export const pauseWorkflowInstance = (id) => {
  return request({
    url: `/workflows/instances/${id}/pause`,
    method: 'post'
  })
}

// 恢复工作流实例
export const resumeWorkflowInstance = (id) => {
  return request({
    url: `/workflows/instances/${id}/resume`,
    method: 'post'
  })
}

// 重试工作流实例
export const retryWorkflowInstance = (id, data) => {
  return request({
    url: `/workflows/instances/${id}/retry`,
    method: 'post',
    data
  })
}

// 取消工作流实例
export const cancelWorkflowInstance = (id) => {
  return request({
    url: `/workflows/instances/${id}/cancel`,
    method: 'post'
  })
}

// 获取工作流实例日志
export const getWorkflowInstanceLogs = (id, params) => {
  return request({
    url: `/workflows/instances/${id}/logs`,
    method: 'get',
    params
  })
}

// 删除工作流实例
export const deleteWorkflowInstance = (id) => {
  return request({
    url: `/workflows/instances/${id}`,
    method: 'delete'
  })
}
